package com.gking.processHarvest.controller;


import com.gking.processHarvest.common.Res;
import com.gking.processHarvest.entity.Notes;
import com.gking.processHarvest.service.Notes.NotesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/note")
public class NotesController {

    @Autowired
    private NotesService notesService;

    /**
     * 创建笔记
     *
     * @param notes 笔记内容详情
     * @return s
     */
    @PostMapping("/create")
    public Res<String> create(@RequestBody Notes notes) {
        log.warn("传递过来的笔记信息为： {}", notes);
        return notesService.create(
                notes.getProjectId(), notes.getExampleId(),
                notes.getContent(), notes.getEditContent());
    }

    /**
     * 更新笔记
     *
     * @param notes 笔记内容详情
     * @return s
     */
    @PutMapping("/update")
    public Res<String> update(@RequestBody Notes notes) {
        log.warn("传递过来的笔记信息为： {}", notes);
        return notesService.update(notes.getId(), notes.getContent(), notes.getEditContent());
    }


    /**
     * 删除笔记
     *
     * @param id 笔记id
     * @return s
     */
    @DeleteMapping("/delete/{id}")
    public Res<String> delete(@PathVariable String id) {
        log.warn("要删除的笔记 id 为： {}", id);
        return notesService.delete(id);
    }

    /**
     * 获取笔记详情
     *
     * @param noteId 笔记id
     * @return s
     */
    @GetMapping("/detail/{noteId}")
    public Res<Notes> getDetail(@PathVariable String noteId) {
        log.warn("要获取详情的笔记 id 为： {}", noteId);
        if (noteId == null || noteId.equals("")) return Res.error("请将笔记id参数补充完整");
        return notesService.getDetail(noteId);
    }
}
